﻿using System;
using System.Threading.Tasks;
using FortuneUniverse.Fortune.Algorithms;

namespace FortuneUniverse.Fortune.Dyson
{
  public class PlanetAlgorithm2 : PlanetAlgorithm
  {
    public override void GenerateTerrain(double modX, double modY)
    {
      modX = (3.0 - modX - modX) * modX * modX;
      double num = 0.0035;
      double num2 = 0.025 * modX + 0.0035 * (1.0 - modX);
      double num3 = 0.0035;
      double num4 = 3.0;
      double num1 = 1.0 + 1.3 * modY;
      num *= num1;
      num2 *= num1;
      num3 *= num1;
      URandom1 urandom1 = new URandom1(this.planet.seed);
      int seed = urandom1.Next();
      urandom1.Next();
      SimplexNoise simplexNoise = new SimplexNoise(seed);
      PlanetRawData data = this.planet.data;
      Parallel.For(0, data.dataLength, (Action<int>) (i =>
      {
        double num5 = 0.6 / (Math.Abs(simplexNoise.Noise3DFBM((double) data.vertices[i].x * (double) this.planet.radius * num, (double) data.vertices[i].y * (double) this.planet.radius * num2, (double) data.vertices[i].z * (double) this.planet.radius * num3, 6, 0.45, 1.8) * num4 + num4 * 0.4) + 0.6) - 0.25;
        double num6 = num5 >= 0.0 ? num5 : num5 * 0.3;
        data.heightData[i] = (ushort) (((double) this.planet.radius + num6 + 0.1) * 100.0);
      }));
    }
  }
}
